package com.wltjack.springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.wltjack.springboot.dto.UserDto;
import com.wltjack.springboot.vo.UserVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper // @Mapper是mybatis框架用于声明Mapper接口的注解
public interface UserMapper extends BaseMapper<UserVO> {


    /**
     * 查询所有用户
     */
    @Select("SELECT t.ID as id,t.USER_NAME as userName,t.`NAME` as name,t.ADDRESS as address FROM crm.user t")
    List<UserVO> getAllUsers();

    @Select("SELECT t.ID as id,t.USER_NAME as userName,t.`NAME` as name,t.ADDRESS as address FROM crm.user t where t.ID=#{id}")
    UserVO getUserDetailById(Integer id);

    /**
     * 根据id删除用户
     */
    @Delete("DELETE FROM crm.user WHERE ID=#{id}")
    void deleteUserById(Integer id);

    /**
     * 新增用户
     */
    @Insert("INSERT INTO crm.user (`USER_NAME`, `NAME`, `ADDRESS`) VALUES (#{userName}, #{name}, #{address})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int insertUser(UserVO userVO);

    /**
     * 修改用户
     */
    @Update("UPDATE crm.user SET `USER_NAME`=#{userName}, `NAME`=#{name}, `ADDRESS`=#{address} WHERE `ID`=#{id}")
    int updateUser(UserVO userVO);

    /**
     * 新增用户记录
     */
    int insertSelective(UserVO userVO);

    /**
     * 更新用户记录
     */
    int updateByPKSelective(UserVO userVO);

    /**
     * 查询用户列表
     */
    List<UserVO> selectUserList(UserDto userDto);

}
